package ${packagePrefix}.application.assembler;

import ${packagePrefix}.client.dto.command.${domainObjectName}AddCmd;
import ${packagePrefix}.client.dto.command.${domainObjectName}ModifyCmd;
import ${packagePrefix}.client.dto.data.${domainObjectName}DTO;
import ${packagePrefix}.domain.model.${tableName?lower_case}.${domainObjectName};
import org.mapstruct.*;
import org.springframework.stereotype.Component;
<#if hasDateFields>
import java.util.Date;
</#if>

/**
 * ${entityComment}对象转换器
 * 使用MapStruct自动生成对象转换代码
 */
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface ${domainObjectName}Assembler {

    /**
     * 将领域对象转换为DTO
     */
    ${domainObjectName}DTO toDTO(${domainObjectName} ${domainObjectName?uncap_first});

    /**
     * 将新增命令转换为领域对象
     */
    @Mapping(target = "id", ignore = true)
<#if hasDateFields>
    @Mapping(target = "createTime", expression = "java(new java.util.Date())")
    @Mapping(target = "updateTime", expression = "java(new java.util.Date())")
</#if>
    ${domainObjectName} toEntity(${domainObjectName}AddCmd cmd);

    /**
     * 将修改命令更新到领域对象
     */
    @Mapping(target = "id", ignore = true)
<#if hasDateFields>
    @Mapping(target = "createTime", ignore = true)
    @Mapping(target = "updateTime", expression = "java(new java.util.Date())")
</#if>
    void updateEntity(@MappingTarget ${domainObjectName} ${domainObjectName?uncap_first}, ${domainObjectName}ModifyCmd cmd);
} 